package com.clearance.mine_clearance.untils;
import com.clearance.mine_clearance.entry.Config;
import com.clearance.mine_clearance.entry.TgUser;
import com.clearance.mine_clearance.mapper.TgUserNapper;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;

public class InviteLinkUntils {


    private static TgUserNapper tgUserNapper;


    static {
        tgUserNapper = (TgUserNapper) BeanUtils.getBean("tgUserNapper");
    }

    public static SendMessage promotionLink(Update update) {
        CallbackQuery callbackQuery = update.getCallbackQuery();
        User from = callbackQuery.getFrom();
        String tgUserId = from.getId().toString();
        TgUser tgUser = tgUserNapper.selectByTgId(tgUserId);
        SendMessage sendMessage = myLinkInfo(tgUser);
        sendMessage.setReplyToMessageId(callbackQuery.getMessage().getMessageId());
        return sendMessage;
    }


    public static String getChatInviteIinkUrl(TgUser tgUser) {
        Config config = RedisUntils.getConfig();
        return config.getBotUrl()+"?start="+tgUser.getTgId();
    }


    public static SendMessage myLinkInfo(TgUser tgUser) {
        Config config = RedisUntils.getConfig();
        String chatInviteLinkUrl = tgUser.getChatInviteLinkUrl();
        String text = "@" + tgUser.getUserName() + "，您的专属链接为：" + chatInviteLinkUrl + ",\n" +
                "用户加入后自动成为您的下级用户，用户发包盈利后您将获得1.5%的抽成";
        return SendMessageUntils.initSendMessage(config.getGroupChatId(), text);
    }
}
